package com.gwz.bus.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.gwz.bus.constast.BUSConstast;
import com.gwz.bus.service.CustomerService;
import com.gwz.bus.vo.CustomerVo;
import com.gwz.sys.utils.DataGridView;
import com.gwz.sys.utils.ResultObj;

@RestController
@RequestMapping("customer")
public class CustomerController {
	
	@Autowired
	private CustomerService customerService;
	
	@RequestMapping("loadAllCustomer")
	public DataGridView loadAllCustomer(CustomerVo  customerVo) {
		customerVo.setAvailable(BUSConstast.BUS_AVAILABLE_TRUE);
		return customerService.queryAllCustomer(customerVo);
	}
	
	@RequestMapping("addCustomer")
	public ResultObj addCustomer(CustomerVo customerVo) {
		ResultObj resultObj = new ResultObj(200, "添加成功");
		try {
			customerService.addCustomer(customerVo);
			return resultObj;
		} catch (Exception e) {
			resultObj.setCode(-1);
			resultObj.setMsg("添加失败");
			e.printStackTrace();
			return resultObj;
		}
	}
	
	@RequestMapping("updateCustomer")
	public ResultObj updateCustomer(CustomerVo customerVo) {
		ResultObj resultObj = new ResultObj(200, "修改成功");
		try {
			customerService.updateCustomer(customerVo);
			return resultObj;
		} catch (Exception e) {
			resultObj.setCode(-1);
			resultObj.setMsg("修改失败");
			e.printStackTrace();
			return resultObj;
		}
	}
	
	@RequestMapping("deleteCustomer")
	public ResultObj deleteCustomer(CustomerVo customerVo) {
		ResultObj resultObj = new ResultObj(200, "删除成功");
		try {
			customerService.deleteCustomer(customerVo);
			return resultObj;
		} catch (Exception e) {
			resultObj.setCode(-1);
			resultObj.setMsg("删除失败");
			e.printStackTrace();
			return resultObj;
		}
	}
	
	@RequestMapping("batchDelete")
	public ResultObj batchDelete(CustomerVo customerVo) {
		ResultObj resultObj = new ResultObj(200, "删除成功");
		try {
			customerService.batchDelete(customerVo);
			return resultObj;
		} catch (Exception e) {
			resultObj.setCode(-1);
			resultObj.setMsg("删除失败");
			e.printStackTrace();
			return resultObj;
		}
	}
	
}
